package org.blogwu.learn.leetcode.链表;

public class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
    }

    ListNode(int x, ListNode next) {
        val = x;
        this.next = next;
    }

    @Override
    public String toString() {
        StringBuilder string = new StringBuilder();
        ListNode node = this;
        int i = 0;
        while (node != null) {
            if (i != 0) {
                string.append(", ");
            }

            string.append(node.val);
            node = node.next;
            i++;
        }
        string.append("]");
        string.insert(0, "size=" + i + "[ ");
        return string.toString();
    }
}
